public class Test {

    //移动零
    public void moveZeroes(int[] nums) {
        int cur = 0;
        int dest = -1;
        for(cur = 0; cur < nums.length; cur++) {
            if(nums[cur] != 0) {
                dest++;
                int tmp = nums[dest];
                nums[dest] = nums[cur];
                nums[cur] = tmp;
            }
        }
    }

    //直接插入排序
    public static void insertSort(int[] arr) {
        for (int i = 1; i < arr.length; i++) {
            int tmp = arr[i];
            int j = i-1;
            for (; j >= 0; j--) {
                if(arr[j] > tmp) {
                    arr[j+1] = arr[j];
                } else {
                    break;
                }
            }
            arr[j+1] = tmp;
        }
    }

    //希尔排序
    public static void shellSort(int[] arr) {
        int gap = arr.length;
        while(gap > 1) {
            gap /= 2;
            shell(arr,gap);
        }
    }

    private static void shell(int[] arr, int gap) {
        for (int i = gap; i < arr.length; i++) {
            int j = i - gap;
            int tmp = arr[i];
            for (; j >= 0; j-=gap) {
                if(arr[j] > tmp) {
                    arr[j+gap] = arr[j];
                } else {
                    break;
                }
            }
            arr[j+gap] = tmp;
        }
    }

    public static void selectSort(int[] arr) {
        for (int i = 0; i < arr.length; i++) {
            int min = i;
            for (int j = i+1; j < arr.length; j++) {
                if(arr[min] > arr[j]) {
                    min = j;
                }
            }
            int tmp = arr[i];
            arr[i] = arr[min];
            arr[min] = tmp;
        }
    }

    //复写0
    public void duplicateZeros(int[] arr) {
        for(int i = 0; i < arr.length-1; i++) {
            if(arr[i] == 0) {
                for(int j = arr.length-2; j > i; j--) {
                    arr[j+1] = arr[j];
                }
                arr[++i] = 0;
            }
        }
    }

    public void heapSort(int[] arr) {
        //建小堆

    }

    public static void createHeap(int[] arr) {

    }

    public static void main(String[] args) {
        int[] arr = {4,8,2,15,75,0,14,23,1};
        selectSort(arr);
        System.out.println();
    }
}
